
#include "fetal.h"

#define MaxDegree 100;

typedef struct{
	int CoffArray[MaxDegree + 1];
	int HighPower;
} * Polynomial;

void ZeroPolynomial(Polynomial Poly){
	int i;
	for(i = 0; i<= MaxDegree; i++){
		Poly->CoffArray[i] = 0;
	}
	Poly->HighPower  = 0;

}

void AddPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial Polysum){
	int i;

	ZeroPolynomial( Polysum );
	Polysum->HighPower = Max(Poly1->HighPower, Poly2->HighPower);

	for( i = Polysum->HighPower; i >=0; i--){
		Polysum->CoffArray[i] = Poly1->CoffArray[i] + Poly2->CoffArray[i];
	}
}

void MultPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolyProd){
	int i,j;

	ZeroPolynomial(PolyProd);
	PolyProd->HighPower = Poly1->HighPower + Poly2->HighPower;

	if(PolyProd->HighPower > MaxDegree){
		Error("Exceeded array size");
	}else{
		for(i=0; i <= Poly1->HighPower; i++){
			for(j = 0; j<= Poly2->HighPower;j++){
				PolyProd->CoffArray[i+j] += Poly1->CoffArray[i] * Poly2->CoffArray[j];
			}
		}
	}

}